<template>
  <div>
    <el-table
      :data="specsList"
      style="width: 100%"
      border
      row-key="id"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="id" label="规格编号"></el-table-column>
      <el-table-column prop="specsname" label="规格名称"></el-table-column>
      <el-table-column label="规格属性">
        <template slot-scope="scope">
          <el-tag type="primary" v-for="(item,index) in scope.row.attrs" :key="index">{{item}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-button type="primary" @click="start(scope.row.id)">启用</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="change(scope.row.id)">编辑</el-button>
          <v-delete @del="del(scope.row.id)"></v-delete>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :total="Number(specsCount)" :page-size="5" @current-change="onClick"></el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { specsDel } from "../../../request/api";
export default {
  data() {
    return {};
  },
  props: ["flag","long"],
  computed: {
    ...mapGetters({
      specsList: "specs/specsList",
      specsCount:"specs/specsCount"
    })
  },
  components: {},
  methods: {
    ...mapActions({
      reqSpecsList: "specs/reqSpecsList",
      reqSpecsInfo:"specs/reqSpecsInfo"
    }),
    //启动
    start() {},
    //编辑
    change(id) {
      this.flag.isShow = true;
      this.flag.isAdd = false;
      this.reqSpecsInfo(id)
    },
    //删除
    del(id) {
      specsDel({ id: id });
      this.reqSpecsList(this.long);
    },
    onClick(e){
      this.long.page = e
      this.reqSpecsList(this.long)
    }
  }
};
</script>
<style lang='less' scoped>
img {
  width: 100px;
  height: 100px;
}
</style>